var $$scope;
var $CertusFormAjax;
var $CertusJsonAjax;
var $fileListService;

// 点击输入请购单号
function addNo() {
    layer.prompt({
        title: '请输入请购单号，并确认！',
        formType: 3
    }, function (text, index) {
        layer.close(index);
        $CertusFormAjax.ajax("purchase/verifyAgreementSubmit",{brCode:text},function(res){
            if(res.data){
                if(res.data == "success"){
                    layer.msg('请购单号：' + text);
                    location.href='#/addAgreement/'+text;
                }else{
                    layer.msg("请购单无法使用");
                }
            }
        })

    });
}

// 报价协议清单 agreementList
var agreementColumns = [{
    id: 'buyingRequisitionCode',
    title: '请购单编号',
    type: 'string',
    width: 250,
    columnClass: 'text-center',
}, {
    id: 'pcsCode',
    title: '比价单编号',
    type: 'string',
    width: 250,
    columnClass: 'text-center',
}, {
    id: 'contractCode',
    title: '合同编号',
    type: 'string',
    width: 180,
    columnClass: 'text-center',
}, {
    id: 'affiliateName',
    title: '归属分公司',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'supplierName',
    title: '供应商名称',
    type: 'string',
    // width: 150,
    columnClass: 'text-center',
}, {
    id: 'priceDiscount',
    title: '价格(含税&折扣)',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
    }
}, {
    id: 'processEnd',
    title: '审批状态',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        if(record.processEnd == "YES"){
            return "完成";
        }else if(record.processEnd == "SHUT"){
            return "终结";
        }
        return "进行中";
    }
}, {
    id: 'deliveryDate',
    title: '交货期',
    type: 'string',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'guaranteeDate',
    title: '质保期',
    type: 'string',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'paymentMethod',
    title: '付款方式',
    type: 'string',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'agreementMsg',
    title: '留言',
    type: 'string',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'operation',
    title: '操作',
    width: 60,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        // content += '<button class="btn btn-xs btn-info" data-toggle="modal" href="#myModal"><i class="icon-cloud-download"> 附件</i></button>';
        // content += '  ';

        content += '<a class="btn btn-xs btn-primary" href="#/selAgreement/'+ record.agreementCode+'"><i class="icon-eye-open"></i>  查看</a>';
        // content += '  ';
        // content += '<a class="btn btn-xs btn-danger" href="#/edAgreement"><i class="icon-retweet"></i>  协议变更</a>';
        return content;
    }
}, ];

// 点击协议作废提示效果
function del() {
    layer.confirm('确认作废此协议合同？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        layer.msg('执行成功！', {
            icon: 1
        });
    });
}


// // 请购清单
// var purchaselistColumns = [{
//         id: 'proList',
//         title: '类目',
//         type: 'string',
//         width: 75,
//         columnClass: 'text-center',
//     }, {
//         id: 'proType',
//         title: '类别',
//         type: 'string',
//         width: 75,
//         columnClass: 'text-center',
//     }, {
//         id: 'proName',
//         title: '名称',
//         type: 'string',
//         width: 100,
//         columnClass: 'text-center',
//     }, {
//         id: 'spec',
//         title: '品名及规格',
//         type: 'string',
//         width: 100,
//         columnClass: 'text-center',
//     }, {
//         id: 'number',
//         title: '数量',
//         type: 'string',
//         width: 100,
//         columnClass: 'text-center',
//     }, {
//         id: 'price',
//         title: '单价',
//         type: 'string',
//         width: 100,
//         columnClass: 'text-center',
//     }, {
//         id: 'sum',
//         title: '总价',
//         type: 'string',
//         width: 100,
//         columnClass: 'text-center',
//     }, {
//         id: 'message',
//         title: '备注',
//         type: 'string',
//         columnClass: 'text-left',
//     },
//     // {
//     //     id: 'operation',
//     //     title: '操作',
//     //     width: 150,
//     //     type: 'string',
//     //     columnClass: 'text-center',
//     //     resolution: function (value, record, column, grid, dataNo, columnNo) {
//     //         var content = '';
//     //         content += '<button class="btn btn-xs btn-primary"><i class="icon-eye-open"></i>  查看供应商报价</button>';
//     //         return content;
//     //     }
//     // }
// ];
// var purchaselistOption = {
//     lang: 'zh-cn',
//     ajaxLoad: false,
//     // loadURL:'url',
//     exportFileName: '请购清单',
//     datas: [{
//         proList: '设备',
//         proType: '服务器',
//         proName: '浪潮服务器',
//         spec: '测试数据',
//         number: '100',
//         price: '￥99.00元',
//         sum: '￥999.00元',
//         message: '备注测试数据'
//     }, {
//         proList: '设备',
//         proType: '硬件',
//         proName: '华硕笔记本',
//         spec: '测试数据',
//         number: '100',
//         price: '￥99.00元',
//         sum: '￥999.00元',
//         message: '备注测试数据'
//     }, {
//         proList: '服务',
//         proType: '服务',
//         proName: '售后服务',
//         spec: '测试数据',
//         number: '100',
//         price: '￥99.00元',
//         sum: '￥999.00元',
//         message: '备注测试数据'
//     }, ],
//     columns: purchaselistColumns,
//     gridContainer: 'purchaselistContainer',
//     toolbarContainer: 'purchaselistToolBarContainer',
//     tools: '',
//     check: true,
//     checkWidth: 20,
//     // onCheck : function(isChecked, record, grid, dataNo, row, extraCell, e){
//     // 	var log = '<p>复选事件触发。是否复选：'+isChecked+'；触发行坐标：'+dataNo+'。</p>';
//     // 	appendLog_2_1_11(log);
//     // },
//     pageSize: 10,
//     pageSizeLimit: [10, 15, 20]
// };
// var purchaselistGrid = $.fn.dlshouwen.grid.init(purchaselistOption);
// $(function () {
//     purchaselistGrid.load();
// });


// 报价列表-历史记录
var pricelogColumns = [{
        id: 'pname',
        title: '采购物资名称',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'name',
        title: '供应商名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'address',
        title: '地点',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'tell',
        title: '联系方式',
        type: 'string',
        width: 110,
        columnClass: 'text-center',
    }, {
        id: 'tnumber',
        title: '数量',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
    }, {
        id: 'oneprice',
        title: '单价',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
        }
    }, {
        id: 'price',
        title: '总价(含税&折扣)',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
        }
    }, {
        id: 'msg',
        title: '备注说明',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'prdmsg',
        title: '规格和参数',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'dateOfDelivery',
        title: '交货期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'guaranteeDate',
        title: '质保期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'paytype',
        title: '付款方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    },
    {
        id: 'test',
        title: '优劣势',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'operation',
        title: '操作',
        width: 60,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-info" data-toggle="modal" href="#myModal"><i class="icon-cloud-download"></i>  报价单</button>';
            return content;
        }
    },
];
var pricelogOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    // loadURL:'url',
    exportFileName: '报价列表-历史记录',
    datas: [{
        pname: '浪潮服务器',
        name: '北京市创瑞丰系统集成有限公司',
        address: '北京',
        tell: '张三12345678901',
        oneprice: '￥858585.58元',
        price: '￥999,999,999.00元',
        tnumber: '12321',
        msg: '价格优惠套餐……',
        prdmsg: '20*54cm，标配网络拓展口',
        pulltime: '5个工作日',
        dtime: '三年质保',
        paytype: '票到60天付款',
        test: '该供应商为我司长期合作供应商，一直为我司提供浪潮服务器及其配件，质量相对有保障，且价格相对其他两家较低。'
    }],
    columns: pricelogColumns,
    gridContainer: 'pricelogContainer',
    toolbarContainer: 'pricelogToolBarContainer',
    extraWidth: 20,
    tools: '',
    pageSize: 10,
    pageSizeLimit: [10, 15, 20]
};
var pricelogGrid = $.fn.dlshouwen.grid.init(pricelogOption);
$(function () {
    pricelogGrid.load();
});

// 报价单列表
var supplierColumns = [{
    id: 'buyingRequisitionCode',
    title: '请购单编号',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'pcsCode',
    title: '比价单编号',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'createTime',
    title: '申请时间',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
    resolution:function (value, record, column, grid, dataNo, columnNo){
        var date = new Date(record.createTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'purchaseMsg',
    title: '留言',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'status',
    title: '审批状态',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        if(record.processEnd == 'YES'){
            return "审批完成";
        }
        return "流程进行中";
    }
}];
// 供应商报价协议提交判断
function shpriceox() {
    // 勾选条目
    var recordCount = purchaselistGrid.getCheckedRecords().length;
    // 勾选数据
    var checkValue = purchaselistGrid.getCheckedRecords();
    // console.log(checkValue);

    if (recordCount == 0) {
        layer.msg("请先勾选协议中包含的采购条目，再进行提交！");
        return;
    } else {
        layer.msg("请上传报价协议！");
        return;
    }
}

// 页面定位效果
function toBox(id) {
    $(id)[0].scrollIntoView();
}

// 上传文件展示隐藏效果
function shuplod() {
    var status = $(".shuplod").css('display');
    if (status == "none") {
        $(".shuplod").show();
        var boxId = "#shuplod";
        toBox(boxId);
    } else {
        $(".shuplod").hide();
    }
}


// 请购清单
var pltlogColumns = [{
    id: 'cateName',
    title: '类目',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'className',
    title: '类别',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'name',
    title: '名称',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'desc',
    title: '品名及规格',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'quantity',
    title: '数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'singlePrice',
    title: '单价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
    }
}, {
    id: 'amount',
    title: '总价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
    }
}, {
    id: 'remark',
    title: '备注',
    type: 'string',
    columnClass: 'text-left',
}, ];